<template>
	<view>
		
		<!--删除群聊成员 -->
			
		<view class="content">
			<view class="search-form round">
				<text class="wlIcon-sousuo1 text-bold color-search"></text>
				<input type="text" 
				v-model="name"
				confirm-type="search" 
				placeholder-style="color: #ccc" 
				placeholder="搜索" 
				@confirm="onSearchInputConfirmed"
				@input="onSearchInputChanged" />
			</view>
			
			
			<view class="item" v-for="(item,index) in dataList" :key="index">
				<radio :value="String(item.id)"
				:checked="item.selected ? true : false" 
				 @click="changeRadio(index)"></radio>
				
				<image :src="item.avatar"
				class="nicknameImage"
				></image>
				
				<view class="nickname text-cut">{{item.nickname || ''}}</view>
			</view>
		</view>
		
		
		<uni-load-more :status="status" :content-text="contentText" />
		
		<view class="fixed-btn">
			<view class="btn" @click="submit()">完成</view>
		</view>
		
	</view>
	
</template>

<script>
export default {
	data() {
		return {
			user_ids:[],
			name:'',
			group_id:0,
			
			dataList: [],
			reload: false, //判断是否上拉
			total: 0, //数据量
			current_page: 1, //当前页码
			last_page: 1, //总页码
			status: 'more',
			contentText: {
				contentdown: ' ',
				contentrefresh: '加载中',
				contentnomore: ''
			}
		}
	},
	onPullDownRefresh() {
		this.current_page = 1;
		this.reload = true;
		this.loadData();
	},
	onReachBottom() {
		//判断是否最后一页
		if (this.current_page >= this.last_page) {
			this.status = 'noMore';
		} else {
			this.reload = false;
			this.current_page = this.current_page + 1; //页码+1
			this.status = 'loading';
			this.loadData();
		}
	},
	onLoad(option) {
		if(option.group_id){
			this.group_id = option.group_id;
		}
		
		this.loadData();
	},
	methods: {
		loadData(value){
			let request = {};
			request.id = this.group_id;
			request.page = this.current_page;

			if(value){
				request.name = value;
			}
			
			uni.request({
				url: '/im/groupuserlist',
				method: 'GET',
				data: request,
				success: res => {
					console.log("loadData", res);
					
					uni.stopPullDownRefresh();
					res.data.data.forEach(function(value,index){
						 value.selected = false;
					});
					
					this.dataList = this.reload ? res.data.data : this.dataList.concat(res.data.data);//数据 追加
					this.total = res.data.total; //数据量
					this.current_page = res.data.current_page; //当前页码
					this.last_page = res.data.last_page; //总页码
					this.status = res.data.total == 0 ? 'noMore' : 'more';
				}
			});
		},
		submit(){
			let _this = this;
			
			this.user_ids = [];
			this.dataList.forEach(function(value,index){
				if(value.selected){
					_this.user_ids.push(value.id);
				}
			})
			
			uni.request({
				url: '/im/groupuserdel',
				method: 'POST',
				data: {
					user_ids: this.user_ids.join(','),
					id: this.group_id
				},
				success: res => {
					if(res.code == 1 || res.res.code == 1){
						this.$wanlshop.msg('删除成功');
						uni.switchTab({
							url: '/pages/chat'
						})
					}else{
						this.$wanlshop.msg(res.msg);
					}
				}
			});
		},
		changeRadio(index){
			if (this.dataList[index].selected) {
	            this.dataList[index].selected = false;
	        }
	        // 未选中状态下点击
	        else {
	            this.dataList[index].selected = true;
	        }
		},
		onSearchInputChanged(event) {
			let value = event.detail.value;
			if (!value) {
				return;
			} else {
				this.current_page = 1;
				this.reload = true;
				this.loadData(value);
			}
		},
		onSearchInputConfirmed(event) {
			let value = event.detail.value;
			if (!value) {
				this.current_page = 1;
				this.reload = true;
				this.loadData(value);
				//uni.showModal({ title: '提示', content: '请输入内容。' });
			} else {
				uni.hideKeyboard();
				this.current_page = 1;
				this.reload = true;
				this.loadData(value);
			}
		},
	}
}	
</script>

<style lang="scss" scoped>
.search-form{
	background-color: #F7F7F7;
	margin-bottom: 24rpx;
	height: 70rpx;
	display: flex;
	align-items: center;
	padding-left: 32rpx;
}

.content{
	background: #ffffff;
	border-radius: 40rpx 40rpx 0rpx 0rpx;
	padding: 24rpx;
	height: 82vh;
	overflow-y: auto;
}

.color-search{
	color: #C7C7C7;
	margin-right: 20rpx;
}

.nicknameImage{
	width: 70rpx;
	height: 70rpx;
	border-radius: 50%;
	margin-left: 17rpx;
	margin-right: 17rpx;
}

.nickname{
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #292929;
	width: 556rpx;
	border-bottom: 1rpx solid #EBEBEB;
	padding-bottom: 42rpx;
	padding-top: 42rpx;
}
.item{
	display: flex;
	align-items: center;
}

.btn{
	width: 702rpx;
	height: 88rpx;
	background: $MAIN_COLOR;
	border-radius: 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #ffffff;
}

.fixed-btn{
	display: flex;
	align-items: center;
	justify-content: center;
	position: fixed;
	bottom: 60rpx;
	left: 24rpx;
}
</style>